{% extends "configuration/left_menu.html" %}

{% block right_content %}

<div id="right_menu">

   <div class="row">
        <div class="col-md-2">
            <h3><strong>编辑配置元数据</strong></h3>
        </div>
        <div class="col-md-10">
            <div class="alert-msg"></div>
        </div>

    </div>
    <hr/>
	<div class="column-row">
            <input id="page" value="{{ page }}" style="display: none;">
            <input id="config_meta_id" value="{{ config_meta_info.id }}" style="display: none;">
           <!-- <div class="form-inline"> -->
           <div class="column-text">
                <label class="position_center" for="svn_path">svn仓库路径:</label>
           </div>

           <div class="column-body-single-input-text">
           		<input value="{{ config_meta_info.svn_path }}" id="svn_path" type="text" class="form-control" placeholder="请输入模块配置的svn仓库路径" />
           </div>
    </div><br>

    <div class="column-row">
        <!-- <div class="form-inline"> -->
           <div class="column-text">
                <label class="position_center" for="manage_path" >管理节点路径:</label>
           </div>

           <div class="column-body-single-input-text">
           		  <input id="manage_path" type="text" class="form-control" placeholder="管理节点路径" value="{{ config_meta_info.manage_path }}" />
           </div>
    </div><br>

	<div class="column-row">

        <!-- <div class="form-inline"> -->
    <div class="column-text">
          <label class="position_center" for="">请选择类型:</label>
    </div>
    <div class="column-body-single-input-text">
     		<select id="category" class="form-control">
           		<option value="{{ config_meta_info.category }}">{{ config_meta_info.category_name }}</option>
              {% for category in categorys %}
                <option value="{{ category.id }}">{{ category.category_name }}</option>

              {% endfor %}
     		</select>
    </div>
  </div><br>

  <div class="column-row">

    	<div class="col-md-2">
    		  <button type="submit" id="cfgmeta_updater" class="btn btn-success" >提交</button>
    	</div>

    	<div class="col-md-2">
    		  <button type="reset" id="reseter" class="btn btn-danger">重置</button>
    	</div>

  </div>
</div>

<script type="text/javascript">
    $('#cfgmeta_updater').click(function() {

        var svn_path = $('#svn_path').val();
        var manage_path = $('#manage_path').val();
        var category_id = $('#category option:selected').val();
        var page = $('#page').val();
        var config_meta_id = $('#config_meta_id').val();

        var url = "{% url 'configuration:updateConfigMeta' %}";

        var postdata = {
            svn_path : svn_path,
            manage_path : manage_path,
            category : category_id,
            page : page,
            id: config_meta_id
        };

        var ret_data = $.ajax({
            url : url,
            type : "POST",
            data : postdata,
            async : false,
            cache : false
        });

        if(ret_data.status == 200) {

            app_res_status = ret_data.responseJSON.status;
            message = ret_data.responseJSON.message;
            page = ret_data.responseJSON.page;

            if(app_res_status == 1) {
                alert_msg('success', message);
                setTimeout(function() {
                  window.location.href="{% url 'configuration:showListForm' %}?page=" + page;
                }, 2500);
            } else {
                alert_msg('danger', message);
            }

        } else {
            alert_msg('danger', "服务器错误!");
        }

    });
</script>

{% endblock %}

